package com.sky.service.impl;

import com.sky.entity.Dish;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealDishMapper;
import com.sky.service.SetMealDishService;
import com.sky.vo.DishItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetMealDishServiceImpl implements SetMealDishService {
	
	@Autowired
	private SetmealDishMapper setmealDishMapper;
	
	@Autowired
	private DishMapper dishMapper;
	
	/**
	 * 根据套餐id查询套餐菜品
	 *
	 * @param setmealId
	 * @return
	 */
	@Override
	public List<DishItemVO> getSetmealDishId(Long setmealId) {
		List<DishItemVO> dishItemVO = new ArrayList<>();
		setmealDishMapper.getSetmealDishId(setmealId).forEach(e -> {
			Dish dish = dishMapper.getDishId(e.getDishId());
			dishItemVO.add(DishItemVO.builder().name(e.getName()).copies(e.getCopies()).image(dish.getImage()).description(dish.getDescription()).build());
		});
		return dishItemVO;
	}
}
